{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7ef6600d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "合并后的Excel表格已保存到 '中诚大厦_合并后数据.xlsx'\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 1. 读取单页Excel文件\n",
    "excel_path_single = '中诚大厦路线规划.xlsx'\n",
    "df_single = pd.read_excel(excel_path_single)\n",
    "\n",
    "# 2. 读取五页Excel文件的所有工作表\n",
    "excel_path_multi = '中诚大厦周边数据表格.xlsx'\n",
    "# 使用pd.read_excel()直接读取所有工作表，返回一个字典\n",
    "dfs_multi = pd.read_excel(excel_path_multi, sheet_name=None)\n",
    "\n",
    "# 3. 合并DataFrame\n",
    "# 将单个工作表的DataFrame与多个工作表的DataFrame合并\n",
    "# 首先，将字典中的所有工作表DataFrame转换为列表\n",
    "sheets_list = list(dfs_multi.values())\n",
    "# 然后将df_single添加到工作表列表中\n",
    "sheets_list.append(df_single)\n",
    "# 最后，使用concat函数合并所有DataFrame\n",
    "combined_df = pd.concat(sheets_list, ignore_index=True)\n",
    "\n",
    "# 4. 保存合并后的表格到新的Excel文件\n",
    "output_excel_path = '中诚大厦_合并后数据.xlsx'\n",
    "combined_df.to_excel(output_excel_path, index=False)\n",
    "\n",
    "print(f\"合并后的Excel表格已保存到 '{output_excel_path}'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "529c3cb8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "合并后的Excel表格已保存到 '良友大厦_合并后数据.xlsx'\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 1. 读取单页Excel文件\n",
    "excel_path_single = '良友大厦路线规划.xlsx'\n",
    "df_single = pd.read_excel(excel_path_single)\n",
    "\n",
    "# 2. 读取五页Excel文件的所有工作表\n",
    "excel_path_multi = '良友大厦周边数据表格.xlsx'\n",
    "# 使用pd.read_excel()直接读取所有工作表，返回一个字典\n",
    "dfs_multi = pd.read_excel(excel_path_multi, sheet_name=None)\n",
    "\n",
    "# 3. 合并DataFrame\n",
    "# 将单个工作表的DataFrame与多个工作表的DataFrame合并\n",
    "# 首先，将字典中的所有工作表DataFrame转换为列表\n",
    "sheets_list = list(dfs_multi.values())\n",
    "# 然后将df_single添加到工作表列表中\n",
    "sheets_list.append(df_single)\n",
    "# 最后，使用concat函数合并所有DataFrame\n",
    "combined_df = pd.concat(sheets_list, ignore_index=True)\n",
    "\n",
    "# 4. 保存合并后的表格到新的Excel文件\n",
    "output_excel_path = '良友大厦_合并后数据.xlsx'\n",
    "combined_df.to_excel(output_excel_path, index=False)\n",
    "\n",
    "print(f\"合并后的Excel表格已保存到 '{output_excel_path}'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bee33a53",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "合并后的Excel表格已保存到 '武银大厦_合并后数据.xlsx'\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 1. 读取单页Excel文件\n",
    "excel_path_single = '武银大厦路线规划.xlsx'\n",
    "df_single = pd.read_excel(excel_path_single)\n",
    "\n",
    "# 2. 读取五页Excel文件的所有工作表\n",
    "excel_path_multi = '武银大厦周边数据表格.xlsx'\n",
    "# 使用pd.read_excel()直接读取所有工作表，返回一个字典\n",
    "dfs_multi = pd.read_excel(excel_path_multi, sheet_name=None)\n",
    "\n",
    "# 3. 合并DataFrame\n",
    "# 将单个工作表的DataFrame与多个工作表的DataFrame合并\n",
    "# 首先，将字典中的所有工作表DataFrame转换为列表\n",
    "sheets_list = list(dfs_multi.values())\n",
    "# 然后将df_single添加到工作表列表中\n",
    "sheets_list.append(df_single)\n",
    "# 最后，使用concat函数合并所有DataFrame\n",
    "combined_df = pd.concat(sheets_list, ignore_index=True)\n",
    "\n",
    "# 4. 保存合并后的表格到新的Excel文件\n",
    "output_excel_path = '武银大厦_合并后数据.xlsx'\n",
    "combined_df.to_excel(output_excel_path, index=False)\n",
    "\n",
    "print(f\"合并后的Excel表格已保存到 '{output_excel_path}'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "92c45d72",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "合并后的Excel表格已保存到 '中诚大厦_合并后数据 .xlsx'\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 1. 读取Excel文件\n",
    "excel_path_single = '中诚大厦路线规划.xlsx'\n",
    "df_single = pd.read_excel(excel_path_single)\n",
    "\n",
    "excel_path_multi = '中诚大厦周边数据表格.xlsx'\n",
    "# 读取五页Excel文件的所有工作表\n",
    "dfs_multi = pd.read_excel(excel_path_multi, sheet_name=None)\n",
    "\n",
    "# 2. 检查和统一列名\n",
    "# 确保df_single和dfs_multi中的每个DataFrame具有相同的列名\n",
    "# 如果需要，可以使用df.rename(columns={})来重命名列\n",
    "\n",
    "# 3. 合并DataFrame\n",
    "# 将dfs_multi中的所有DataFrame合并，然后与df_single合并\n",
    "df_multi = pd.concat(dfs_multi.values(), ignore_index=True)\n",
    "combined_df = pd.concat([df_multi, df_single], ignore_index=True)\n",
    "\n",
    "# 4. 保存合并后的表格到新的Excel文件\n",
    "output_excel_path = '中诚大厦_合并后数据 .xlsx'\n",
    "combined_df.to_excel(output_excel_path, index=False)\n",
    "\n",
    "print(f\"合并后的Excel表格已保存到 '{output_excel_path}'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0987ae71",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
